package cn.edu.scau.dao;

import cn.edu.scau.entity.Care;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

public class CareSqlProvider {

    public String insertSelective(Care record) {
        SQL sql = new SQL();
        sql.INSERT_INTO("care");
        
        if (record.getCustomerid() != null) {
            sql.VALUES("customerID", "#{customerid,jdbcType=INTEGER}");
        }
        
        if (record.getNurseid() != null) {
            sql.VALUES("nurseID", "#{nurseid,jdbcType=INTEGER}");
        }
        
        return sql.toString();
    }

    public String updateByPrimaryKeySelective(Care record) {
        SQL sql = new SQL();
        sql.UPDATE("care");
        
        if (record.getNurseid() != null) {
            sql.SET("nurseID = #{nurseid,jdbcType=INTEGER}");
        }
        
        sql.WHERE("customerID = #{customerid,jdbcType=INTEGER}");
        
        return sql.toString();
    }
    
    public String find(Integer customerid, String customername, Integer nurseid, String nursename){
        SQL sql = new SQL();
        sql.SELECT("customerID, customerName, nurseID, nurseName");
        sql.FROM("care natural join nurse natural join customer");
        if(customerid!=null){
            sql.WHERE(" customerID like concat('%',#{customerid},'%')");
        }
        if(customername!=null){
            sql.WHERE(" customerName like concat('%',#{customername},'%')");
        }
        if(nurseid!=null){
        	sql.WHERE(" nurseID like concat('%',#{nurseid},'%')");
        }
        if(nursename!=null){
            sql.WHERE(" nurseName like concat('%',#{nursename},'%')");
        }
        sql.ORDER_BY("customerID");
        return sql.toString();
    }
    
    
    public String findWithNurseID(Integer customerid, String customername, Integer nurseid, String nursename){
        SQL sql = new SQL();
        sql.SELECT("customerID, customerName, nurseID, nurseName");
        sql.FROM("care natural join nurse natural join customer");
        if(customerid!=null){
            sql.WHERE(" customerID like concat('%',#{customerid},'%')");
        }
        if(customername!=null){
            sql.WHERE(" customerName like concat('%',#{customername},'%')");
        }
        if(nurseid!=null){
        	sql.WHERE(" nurseID = #{nurseid}");
        }
        if(nursename!=null){
            sql.WHERE(" nurseName like concat('%',#{nursename},'%')");
        }
        sql.ORDER_BY("customerID");
        return sql.toString();
    }
    
}